package com.macro.mall.utils;

import java.security.SecureRandom;

/**
 * 订单编号生成工具类
 */
public class OrderNumberUtils {

    private static final SecureRandom RANDOM = new SecureRandom();

    /**
     * 生成指定长度的纯数字订单编号
     * @param length 订单编号的长度
     * @return 纯数字订单编号字符串
     */
    public static String generateNumericOrderNo(int length) {
        if (length <= 0) {
            throw new IllegalArgumentException("长度必须大于0");
        }

        StringBuilder orderNoBuilder = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int digit = RANDOM.nextInt(10); // 生成0-9之间的数字
            orderNoBuilder.append(digit);
        }
        return orderNoBuilder.toString();
    }
}
